/**
 * Copyright (C), 2015-2018, XXX有限公司
 * FileName: LogWarpper
 * Author:   zhouheng
 * Date:     2018/6/23 0:00
 * Description: 操作日志包装类
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.hengby.hengcrud.modular.sys.warpper;

import com.hengby.hengcrud.core.common.factory.ConstantFactory;
import com.hengby.hengcrud.core.util.Contrast;
import com.hengby.hengcrud.core.util.ToolUtil;
import com.hengby.hengcrud.modular.base.wrap.BaseControllerWarpper;

import java.util.Map;

/**
 * 〈一句话功能简述〉<br> 
 * 〈操作日志包装类〉
 *
 * @author zhouheng
 * @create 2018/6/23
 * @since 1.0.0
 */
public class LogWarpper extends BaseControllerWarpper{

    public LogWarpper(Object obj) {
        super(obj);
    }

    @Override
    protected void warpTheMap(Map<String, Object> map) {
        String message = (String) map.get("message");
        String userName = ConstantFactory.me().getUserNameById((Integer) map.get("userid"));

        map.put("userName",userName);

        if (ToolUtil.isNotEmpty(message) && message.length() >= 100){
            // 截断100字符
            map.put("message",message.substring(0,100)+"...");
        }

        if (ToolUtil.isNotEmpty(userName) && userName.indexOf(Contrast.separator) != -1){
            if (userName.split(Contrast.separator).length > 1){
                String[] msg = userName.split(Contrast.separator);

                map.put("regularMessage",msg);
            }else {
                map.put("regularMessage",message);
            }
        }

    }
}